//
   Created by Administrator on 2015/11/7 0007.

extends ./layerout-pc

block style
    style.
        .sign-out {
            margin-top: 1em;
        }

        .cover {
            padding: 30px;
        }

        .cover img {
            width: 100%;
        }

        .del-btn, .edit-btn {
            margin-top: .3em;
            margin-right: .3em;
        }
block content
    nav.teal
        ul.right.hide-on-med-and-down
            li
                a(href="/manage-video") 全部
            each value, key in list.group
                li
                    a(href="/manage-video?groupid=#{key}")= value
            li
                a(href="/add-video", target="_blank") 添加新视频
            li
                a(href="/menu") 菜单管理
            li
                a(href="/sign-out") 退出
        ul#slide-out.side-nav
            each value, key in list.group
                li
                    a(href="/manage-video?groupid=#{key}")= value
            li
                a(href="/add-video", target="_blank") 添加新视频
            li
                a(href="/menu") 菜单管理
            li
                a(href="/sign-out") 退出
        a.button-collapse(href="#", data-activates="slide-out")
            i.mdi-navigation-menu

    .container
        .row
            .row
            .row
                p 微信内部链接以微信地址为准
                label.link
            if list.items
                ul.collapsible(data-collapsible="accordion")
                    each v in list.items
                        li
                            button.right.del-btn.btn.waves-effect.waves-light(data-id=v._id) 删除
                            a.right.edit-btn.btn.waves-effect.waves-light(href="/add-video?id=" + v._id, target="_blank") 编辑
                            .collapsible-header=v.title
                            .collapsible-body
                                p=v.abstract
                                .row
                                    .col.s4
                                        .cover
                                            img(src="/r/" + v.cover)
                                    .col.s8!= v.link
                                p!=v.content
block script
    script.
        $(".button-collapse").sideNav();
        $signout = $('.sign-out-btn')
        $signout.on("click", function () {
            $.ajax("/sign-out", {
                type: "POST",
                data: "",
                contentType: "application/json"
            }).then(function (r) {
                location.href = "/sign-in"
            })
        })

        $del = $(".del-btn")
        $del.on("click", function (e) {
            e.preventDefault();
            $this = $(e.currentTarget);
            id = $this.attr("data-id");

            $.ajax("/delete-video/" + id, {
                type: "POST"
            }).then(function (r) {
                if (r.status == 1) {
                    location.reload()
                } else {
                    alert("删除失败!")
                }
            })
        })

        $(".link").html("微信地址：https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx033d23e4476b3cfc&redirect_uri=" + location.origin + "/video" + location.search + "&response_type=code&scope=snsapi_base&state=123&connect_redirect=1#wechat_redirect")

